package cn.changshengjue.dakong.command;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;

public abstract class SubCommand implements TabExecutor {
	private String name;
	private String usage, description;

	private int argLength = -1;

	public SubCommand(String name) {
		this.name = name;
	}

	public SubCommand(String name, String usage, String description) {
		this.name = name;
		this.usage = usage;
		this.description = description.replace("&", "§");
		argLength = usage.split(" ").length - 1;
	}

	public abstract boolean onCommand(CommandSender sender, Command cmd, String label, String[] args);

	public String getName() {
		return name;
	}

	public String getUsage() {
		return usage;
	}

	public String getDescription() {
		return description;
	}

	public int getArgLength() {
		return argLength;
	}

	// 帮助指令格式
	public void sendHelp(CommandSender sender) {
		if (usage != null && description != null) {
			sender.sendMessage("§7" + getUsage() + " " + getDescription());
		}
	}

	public boolean isNeedArg() {
		boolean result = true;
		if (argLength == -1) {
			result = false;
		}
		if (argLength == 1) {
			result = false;
		}
		return result;
	}


}
